package com.ocom.payconfig.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ocom.common.entity.payconfig.EntityFkUserparamConfig;
import com.ocom.common.enums.DataSourceEnum;
import com.ocom.common.enums.MasterSlaveEnum;
import com.ocom.mysql.aspect.DataSourceAspect;
import com.ocom.payconfig.dao.IDaoFkUserparamConfig;
import com.ocom.payconfig.service.FkUserparamConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FkUserparamConfigServiceImpl extends ServiceImpl<IDaoFkUserparamConfig, EntityFkUserparamConfig> implements FkUserparamConfigService {

    @Autowired
    private IDaoFkUserparamConfig iDaoFkUserparamConfig;

    @DataSourceAspect(type = DataSourceEnum.PART_DB,companyId = "comId",isMaster = MasterSlaveEnum.SLAVE)
    @Override
    public List<EntityFkUserparamConfig> selectkUserparamConfigList(Long comId, Integer merchId) {
        QueryWrapper<EntityFkUserparamConfig> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("com_id",comId);
        queryWrapper.eq("merch_id",merchId);
        return iDaoFkUserparamConfig.selectList(queryWrapper);
    }

    @DataSourceAspect(type = DataSourceEnum.PART_DB,companyId = "comId",isMaster = MasterSlaveEnum.MASTER)
    @Override
    public void deleteFkUserparamConfig(Long comId, Long merchId, Integer accountType) {
        QueryWrapper<EntityFkUserparamConfig> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("com_id",comId);
        queryWrapper.eq("merch_id",merchId);
        queryWrapper.eq("user_type",accountType);
        iDaoFkUserparamConfig.delete(queryWrapper);
    }

    @DataSourceAspect(type = DataSourceEnum.PART_DB,companyId = "comId",isMaster = MasterSlaveEnum.SLAVE)
    @Override
    public EntityFkUserparamConfig selectEntityFkUserparamConfig(Long comId, Long merchId, Integer accountType) {
        QueryWrapper<EntityFkUserparamConfig> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("com_id",comId);
        queryWrapper.eq("merch_id",merchId);
        queryWrapper.eq("user_type",accountType);
        return iDaoFkUserparamConfig.selectOne(queryWrapper);
    }

    @DataSourceAspect(type = DataSourceEnum.PART_DB,companyId = "comId",isMaster = MasterSlaveEnum.MASTER)
    @Override
    public void insetEntityFkUserparamConfig(Long comId, EntityFkUserparamConfig entityFkUserparamConfig) {
        iDaoFkUserparamConfig.insert(entityFkUserparamConfig);
    }

    @Override
    public void UpdateEntityFkUserparamConfig(Long comId, EntityFkUserparamConfig entityFkUserparamConfig) {
        UpdateWrapper<EntityFkUserparamConfig> updateWrapper=new UpdateWrapper<>();
        updateWrapper.eq("com_id",entityFkUserparamConfig.getComId());
        updateWrapper.eq("merch_id",entityFkUserparamConfig.getMerchId());
        updateWrapper.eq("user_type",entityFkUserparamConfig.getUserType());
        iDaoFkUserparamConfig.update(entityFkUserparamConfig,updateWrapper);
    }
}
